package userConsole.service;

import org.json.JSONException;
import org.json.JSONObject;
import userConsole.jdbc.BaseJDBC;
import userConsole.jdbc.UserJDBC;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Godv
 * @version 1.0
 */
public class RegisterService {
    public JSONObject registerUser(String username, String password) throws JSONException {
        Connection connection = BaseJDBC.createConnection();
        UserJDBC userJDBC = new UserJDBC();
        JSONObject jsonObject = new JSONObject();
        try {
            userJDBC.registerUser(connection, username, password);
            jsonObject.put("code", 200);
            jsonObject.put("msg", "注册成功");
        } catch (SQLException e) {
            jsonObject.put("code", 506);
            jsonObject.put("msg", "注册失败");
        }
        return jsonObject;
    }
}
